####################################################################################################
# BASE
####################################################################################################
# Defs
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
set(INC_DIR ${CMAKE_CURRENT_LIST_DIR}/include)

add_library(base STATIC
    ${SRC_DIR}/utils/wazuhProtocol/wazuhRequest.cpp
    ${SRC_DIR}/utils/ipUtils.cpp
    ${SRC_DIR}/utils/stringUtils.cpp
    ${SRC_DIR}/utils/timeUtils.cpp
    ${SRC_DIR}/expression.cpp
    ${SRC_DIR}/parseEvent.cpp
    ${SRC_DIR}/json.cpp
    ${SRC_DIR}/logging.cpp
)
target_include_directories(base
    PUBLIC
    ${INC_DIR}

    PRIVATE
    ${INC_DIR}/base
    ${SRC_DIR}
)
target_link_libraries(base
    PUBLIC
    fmt::fmt-header-only
    spdlog::spdlog
)

# Tests

if(ENGINE_BUILD_TEST)

set(TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test)
set(TEST_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/test/src)
set(UNIT_SRC_DIR ${TEST_SRC_DIR}/unit)

add_library(base_test INTERFACE)
target_include_directories(base_test INTERFACE ${TEST_DIR}/include)
add_library(base::test ALIAS base_test)

add_executable(base_utest
    ${UNIT_SRC_DIR}/stringUtils_test.cpp
    ${UNIT_SRC_DIR}/ipUtils_test.cpp
    ${UNIT_SRC_DIR}/result_test.cpp
    ${UNIT_SRC_DIR}/graph_test.cpp
    ${UNIT_SRC_DIR}/name_test.cpp
    ${UNIT_SRC_DIR}/utils/wazuhProtocol/wazuhRequest_test.cpp
    ${UNIT_SRC_DIR}/utils/wazuhProtocol/wazuhResponse_test.cpp
    ${UNIT_SRC_DIR}/parseEvent_test.cpp
    ${UNIT_SRC_DIR}/dotPath_test.cpp
    ${UNIT_SRC_DIR}/json_test.cpp
    ${UNIT_SRC_DIR}/error_test.cpp
    ${UNIT_SRC_DIR}/timer_test.cpp
    ${UNIT_SRC_DIR}/expression_test.cpp
)
target_include_directories(base_utest
    PRIVATE
    ${TEST_SRC_DIR}
    ${SRC_DIR}
    ${INC_DIR}/base
)
target_link_libraries(base_utest
    PUBLIC
    base::test

    PRIVATE
    base
    GTest::gtest_main
)
gtest_discover_tests(base_utest)

# TODO this test needs to be instantiated alone because the logger is initialized on tests
add_executable(base_logger_utest
    ${UNIT_SRC_DIR}/logger_test.cpp
)
target_include_directories(base_logger_utest
    PRIVATE
    ${TEST_SRC_DIR}
    ${INC_DIR}/base
)
target_link_libraries(base_logger_utest
    PRIVATE
    base
    GTest::gtest_main
)
gtest_discover_tests(base_logger_utest)

endif(ENGINE_BUILD_TEST)
